﻿package mortal.game.view.shopMall.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.game.view.signUp.sevenDayLogin.data.*;
    import mortal.mvc.core.*;

    public class SpecialRebatPanel extends GSprite
    {
        private var _tShopPanicBuyItem:TShopPanicBuyItem;
        private var _shopItem:BaseItem;
        private var _rebateBg:GImageBitmap;
        private var _btn:GLoadingButton;
        private var _propName:GTextFiled;
        private var _oldPrice:GTextFiled;
        private var _buyLimit:GTextFiled;
        private var _leftNum:GTextFiled;
        private var _price:GTextFiled;
        private var _discountIcon:GImageBitmap;
        private var _deleteLine:GBitmap;
        private var _oldPriceIcon:GBitmap;
        private var _priceIcon:GBitmap;
        private var _currentType:int;

        public function SpecialRebatPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._rebateBg = UIFactory.gImageBitmap(ImagesConst.ShopMallRebateBg, 0, 0, this, this.resetPos);
            this._shopItem = UICompomentPool.getUICompoment(ShopSellItem);
            this._shopItem.x = 81;
            this._shopItem.y = 55;
            this._shopItem.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._shopItem);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._propName = UIFactory.gTextField("", 60, 127, 120, 25, this, _loc_1, true);
            _loc_1 = GlobalStyle.textFormatlan.right();
            this._leftNum = UIFactory.gTextField("", 90, 197, 60, 25, this, GlobalStyle.textFormatHuang.right(), true);
            this._buyLimit = UIFactory.gTextField("", 90, 214, 60, 25, this, GlobalStyle.textFormatLv.right(), true);
            this._oldPrice = UIFactory.gTextField("", 90, 231, 60, 25, this, GlobalStyle.textFormatlan.right(), true);
            this._price = UIFactory.gTextField("", 90, 248, 60, 25, this, GlobalStyle.textFormatChen.right(), true);
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35562), 60, 197, 60, 25, this, GlobalStyle.textFormatHuang.center(), true));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35572), 60, 214, 60, 25, this, GlobalStyle.textFormatLv.center(), true));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30060), 60, 231, 60, 25, this, GlobalStyle.textFormatlan.center(), true));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30061), 60, 248, 60, 25, this, GlobalStyle.textFormatChen.center(), true));
            this._oldPriceIcon = UIFactory.gBitmap("", 150, 231, this);
            this._priceIcon = UIFactory.gBitmap("", 150, 248, this);
            this._deleteLine = UIFactory.gBitmap(ImagesConst.deleteLine, 124, 238, this);
            this._discountIcon = UIFactory.gImageBitmap("", 137, 74, this);
            this._btn = UIFactory.gLoadingButton(ResFileConst.RechargeShopBigBuy, 67, 270, 108, 44, this);
            this._btn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap("shopDiscountIcon_0.png", 15, 56, this));
            LoaderHelp.addResCallBack(ResFileConst.rebateShop, this.showSkin);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            SevenDayLoginUtil.removeArrow(this._btn);
            this._oldPrice.dispose(param1);
            this._price.dispose(param1);
            this._propName.dispose(param1);
            this._oldPriceIcon.dispose(param1);
            this._priceIcon.dispose(param1);
            this._deleteLine.dispose(param1);
            this._discountIcon.dispose(param1);
            this._oldPrice = null;
            this._price = null;
            this._propName = null;
            this._oldPriceIcon = null;
            this._priceIcon = null;
            this._deleteLine = null;
            this._discountIcon = null;
            this._buyLimit.dispose(param1);
            this._buyLimit = null;
            this._rebateBg.dispose(param1);
            this._rebateBg = null;
            this._leftNum.dispose(param1);
            this._leftNum = null;
            if (this._btn)
            {
                this._btn.dispose(param1);
                this._btn = null;
            }
            this._shopItem.dispose(param1);
            this._shopItem = null;
            this._tShopPanicBuyItem = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function setMoneyIcon(param1:int) : void
        {
            var _loc_2:* = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this._priceIcon.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this._oldPriceIcon.bitmapData = _loc_2;
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.RechargeShopBigTitle, 50, 19, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.RechargeShopBigTiP, 5, 150, this));
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var _loc_2:Object = {item:this._shopItem, num:1};
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateShopBuyItem, _loc_2));
            SevenDayLoginUtil.removeArrow(this._btn);
            return;
        }// end function

        public function updateShopItem(param1:Object) : void
        {
            this._tShopPanicBuyItem = param1.data as TShopPanicBuyItem;
            this._shopItem.itemData = new ItemData(this._tShopPanicBuyItem.itemCode);
            this._currentType = param1.type;
            if (this._currentType == 0)
            {
                var _loc_5:Boolean = true;
                this.mouseEnabled = true;
                this.mouseChildren = _loc_5;
                this.filters = [];
            }
            else
            {
                var _loc_5:Boolean = false;
                this.mouseEnabled = false;
                this.mouseChildren = _loc_5;
                this.filters = [FilterConst.colorFilter2];
            }
            var _loc_2:* = int(this._shopItem.itemData.itemInfo.effect / this._shopItem.itemData.itemInfo.effectEx * 100);
            if (_loc_2 >= 66)
            {
                _loc_2 = 66;
            }
            else if (_loc_2 <= 40)
            {
                _loc_2 = 40;
            }
            else
            {
                _loc_2 = 64;
            }
            this._discountIcon.imgUrl = "shopDiscountIcon_" + _loc_2 + ".png";
            this.setMoneyIcon(EPriceUnit._EPriceUnitGold);
            this._oldPrice.text = this._tShopPanicBuyItem.price.toString();
            var _loc_3:* = GlobalStyle.textFormatBai.right();
            var _loc_4:* = Cache.instance.shop.getRebateInfoDicByItemCode(this._tShopPanicBuyItem.itemCode);
            if (_loc_4 && _loc_4.remainInfo)
            {
                this._price.text = _loc_4.remainInfo.discount.toString();
                this._leftNum.text = _loc_4.remainInfo.leftAmount.toString();
            }
            if (_loc_4 && _loc_4.playerInfo)
            {
                this._buyLimit.text = _loc_4.playerInfo.amount + "/" + this._tShopPanicBuyItem.buyLimit;
            }
            else
            {
                this._buyLimit.text = 0 + "/" + this._tShopPanicBuyItem.buyLimit;
            }
            this._propName.htmlText = ItemsUtil.getItemName(this._shopItem.itemData);
            return;
        }// end function

        private function resetPos() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            if (this._rebateBg)
            {
                this.addChildAt(this._rebateBg, 0);
            }
            return;
        }// end function

        public function shopShowArrow() : void
        {
            SevenDayLoginUtil.genGiftArrow(this._btn, -15, 21, 2, this._btn.parent);
            return;
        }// end function

    }
}
